Option Explicit On
Option Strict On

Public Class Building
  ' To jest klasa bazowa, z ktrej wyprowadzamy
  ' klasy Apartment, Commercial i Home.

  ' =============== Stae symboliczne ================
  Private Const APARTMENT As Integer = 0
  Private Const COMMERCIAL As Integer = 1
  Private Const HOME As Integer = 2

  ' ================== Dane skadowe  ==================

  Private mAddress As String     ' Adres
  Private mPrice As Double       ' Cena nabycia
  Private mMonthlyPayment As Double  ' Opaty miesiczne
  Private mTaxes As Double       ' Roczne podatki
  Private mType As Integer       ' Typ budynku

  ' ==================== Waciwoci ======================
  Public Property Address() As String ' Waciwo Adres
    Get
      Return mAddress
    End Get

    Set(ByVal Value As String)
      mAddress = Value
    End Set
  End Property

  Public Property PurchasePrice() As Double  ' Waciwo Cena nabycia
    Get
      Return mPrice
    End Get

    Set(ByVal Value As Double)
      mPrice = Value
    End Set
  End Property

  Public Property MonthlyPayment() As Double ' Waciwo Opata miesiczna 
    Get
      Return mMonthlyPayment
    End Get

    Set(ByVal Value As Double)
      mMonthlyPayment = Value
    End Set
  End Property

  Public Property Taxes() As Double   ' Waciwo Podatek od nieruchomoci
    Get
      Return mTaxes
    End Get

    Set(ByVal Value As Double)
      mTaxes = Value
    End Set
  End Property

  Public Property BuildingType() As Integer   ' Waciwo Typ budynku
    Get
      Return mType
    End Get

    Set(ByVal Value As Integer)
      If Value < APARTMENT OrElse Value > HOME Then
        mType = -1  ' bd
      Else
        mType = Value
      End If
    End Set
  End Property

  ' ========================== Metody ========================
  Protected Sub DisplayBaseInfo()
    ' Cel: wywietlanie bazowych danych skadowych 
    Dim BldType As String

    Console.WriteLine("Adres: " & mAddress)
    Console.WriteLine("Cena nabycia: " & FormatMoney(mPrice))
    Console.WriteLine("Opata miesieczna: " & _ 
                       FormatMoney(mMonthlyPayment))
    Console.WriteLine("Podatek od nieruchomosci: " & FormatMoney(mTaxes))
    Select Case mType
      Case APARTMENT
        BldType = "Blok mieszkalny"
      Case COMMERCIAL
        BldType = "Komercyjny"
      Case HOME
        BldType = "Dom"
    End Select
    Console.WriteLine("Typ budynku: " & BldType)
  End Sub

  ' ======================= Programy pomocnicze =====================
  Protected Function FormatMoney(ByVal num As Double) As String
    ' Cel: formatowanie wartoci dolara
    '
    ' Argumenty:
    '  num  Liczba double, ktra jest wartoci w dolarach do formatowania
    '
    ' Zwracana warto:
    '  string   acuch wartoci w formacie dolara 

    Return Format(num, "$##########.00")
  End Function
End Class
